snippet srv.def.tpl
	import $1 from '../models/${1:category}'
	import CODE from '../utils/errcode'

	export default {

		async add (ctx, next) {
			let body = ctx.request.body
			let json = {
				name: body.name
			}
			let result = await $1.findAll({
				where: {
					name: body.name,
					status: CODE.ACTIVE_DATA
				}
			})
			if (result.length > 0) {
				ctx.body = { errcode: CODE.FAIL, msg: 'record exist' }
			} else {
				$1.create(json)
				ctx.body = { errcode: CODE.SUCCESS, msg: 'add sucess' }
			}
		},

		async update (ctx, next) {
			let body = ctx.request.body
			let result = await $1.findAll({
				where: {
					name: body.name
				}
			})
			if (result.length > 0) {
				await $1.update({
					name: body.newname,
					updatedAt: Date.now(),
					version: result[0].version
				}, {
					where: {id: result[0].id}
				})
				ctx.body = { errcode: CODE.SUCCESS, msg: 'update sucess' }
			} else {
				ctx.body = { errcode: CODE.FAIL, msg: 'id not exist' }
			}
		},

		async del (ctx, next) {
			await $1.destroy({
				where: {
					id: ctx.request.body.id
				}
			})
			ctx.body = { errcode: CODE.SUCCESS, msg: 'physical delete sucess' }
		},

		async delete (ctx, next) {
			await $1.update({
				status: CODE.DELETED_DATA,
				deletedAt: new Date().getTime()
			}, {
				where: {id: ctx.request.body.id}
			})
			ctx.body = { errcode: CODE.SUCCESS, msg: 'delete sucess' }
		},

		async findAll (ctx, next) {
			let result = await $1.findAll({
				where: { status: CODE.ACTIVE_DATA }
			})
			ctx.body = result.length
				? { errcode: CODE.SUCCESS, data: result }
				: { errcode: CODE.FAIL, msg: 'not found' }
		},

		async findById (ctx, next) {
			let body = ctx.request.body
			let result = await $1.findAll({
				where: {
					id: body.id,
					status: CODE.ACTIVE_DATA
				}
			})
			ctx.body = result.length
				? { errcode: CODE.SUCCESS, data: result }
				: { errcode: CODE.FAIL, msg: 'not found' }
		}
	}
